package com.lanxin.oa.personnel.service;
import com.lanxin.bean.JcBasicdatavalue;
import com.lanxin.bean.ZzDepartment;
import com.lanxin.bean.ZzEmployee;
import com.lanxin.oa.personnel.dao.DeptDao;
import com.lanxin.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService{

    @Autowired
    private DeptDao deptDao;

//    @Override
//    public List<ZzDepartment> listAllDept(ZzDepartment dept) {
//
//        return deptDao.listDeptAll(dept);
//    }

    @Override
    public List<ZzDepartment> selectDeptService() {
        return deptDao.selectDept();
    }

    @Override
    public List<JcBasicdatavalue> selectJobs() {
        return deptDao.selectBasic();
    }

    @Override
    public boolean selectByNameService(String deptName,Integer oid) {
        ZzDepartment dept=deptDao.selectByName(deptName,oid);
        if(dept!=null){
            return true;
        }
        return false;
    }

    @Override
    public List<ZzDepartment> listDeptName() {
        return deptDao.selectDeptName();
    }

    @Override
    public ZzDepartment deptJob(Integer oid) {
        return deptDao.deptJob(oid);
    }

    @Override
    public List<ZzEmployee> listEmpName(Integer deptid,Integer jobid) {
        return deptDao.selectEmpName(deptid,jobid);
    }

    @Override
    public void insertDept(ZzDepartment dept ,Integer[] jobsid) {
        if(jobsid!=null){
            for(Integer jobid:jobsid){
                System.out.println(jobid);
                JcBasicdatavalue basic=new JcBasicdatavalue();
                basic.setOid(jobid);
                dept.getRoles().add(basic);
            }
            deptDao.add(dept);
        }
    }

    @Override
    public ZzDepartment deptById(Integer oid) {
        return deptDao.selectDeptById(oid);
    }

    @Override
    public void updateDept(ZzDepartment dept ,Integer[] jobsid) {
        if(jobsid!=null){
            for(Integer jobid:jobsid){
                System.out.println(jobid);
                JcBasicdatavalue basic=new JcBasicdatavalue();
                basic.setOid(jobid);
                dept.getRoles().add(basic);
            }
            deptDao.update(dept);
        }
    }

    @Override
    public boolean delete(ZzDepartment dept) {
        try {
            deptDao.delete(dept);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public PageBean<ZzDepartment> getDeptPage(Integer page, Integer pageSize,ZzDepartment dept) {

        return deptDao.selectDeptPage(page,pageSize,dept);
    }


}
